<template>
  <div>
    <Banner :sightName="sightName" :bannerImg="bannerImg" :gallaryImgs="gallaryImgs" />
    <DetailHeader />
    <div class="content">
    <DetailList :list="categoryList" />
    </div>
  </div>
</template>

<script>
import axios from 'axios'
import Banner from './components/Banner'
import DetailHeader from './components/DetailHeader'
import DetailList from './components/DetailList'
export default {
  components: {
    Banner,
    DetailHeader,
    DetailList
  },
  data () {
    return {
      lastId: 0,
      sightName: '',
      bannerImg: '',
      gallaryImgs: [],
      categoryList: []
    }
  },
  methods: {
    getDetailInfo () {
      axios.get('/api/detail.json', {
        params: {
          id: this.$route.params.id
        }
      }).then(this.handleDetailInfoSucc)
    },
    handleDetailInfoSucc (res) {
      res = res.data
      if (res.ret && res.data) {
        let data = res.data
        this.sightName = data.sightName
        this.bannerImg = data.bannerImg
        this.gallaryImgs = data.gallaryImgs
        this.categoryList = data.categoryList
      }
    }
  },
  activated () {
    let currentId = this.$route.params.id
    if (this.lastId !== currentId) {
      this.getDetailInfo()
      this.lastId = currentId
    }
  }
}
</script>

<style lang='stylus' rel='stylesheet/stylus' scoped>
  .content
    height 30rem
</style>
